package com.passioneffect.widgets {
	import flash.display.DisplayObjectContainer;
	import flash.display.Graphics;
	import flash.display.Sprite;
	
	import gs.TweenMax;	

	/**
	 * @author Passion Effect
	 */
	public class AutoPan {

		private var _time : Number=2;
		private var _target : DisplayObjectContainer;
		private var _scale : Number;
		private var mask_mc:Sprite;
		
		public function AutoPan(mc:DisplayObjectContainer,time : Number = 2,scale:Number=1.3) {
			this._scale=scale;
			this._target=mc;
			this._time=time;
			
			mask_mc=new Sprite();
			var g:Graphics=mask_mc.graphics;
			g.clear();
			
			g.lineStyle();
			g.beginFill(0x000000,0);
			g.drawRect(0, 0, _target.width, _target.height);
			g.endFill();
			
			if(_target.parent)_target.parent.addChild(mask_mc);
			
			_target.mask=mask_mc;
			
			
			_target.scaleX=_target.scaleY=scale;
		}
		
		public function open():void{
			TweenMax.to(_target,_time,{scaleX:1,scaleY:1});
		}
		
		public function close(skip:Boolean=false):void{
			if(!skip){
				TweenMax.to(_target,_time,{scaleX:_scale,scaleY:_scale});
			}else{
				TweenMax.to(_target,0,{scaleX:_scale,scaleY:_scale});
			}
		}
		
		
	}
}
